public class MyBlockQueue {
    private int[] elem=new int[1_0000];
    private int head=0;
    private int tail=0;
    public int size=0;

    public void put(int val){
        synchronized (this) {
            while (size == elem.length) {
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            elem[tail] = val;
            tail = (tail + 1) % elem.length;
            size++;
            this.notify();
        }
    }

    public Integer take() {
        int val=0;
        synchronized (this) {
            if (size == 0) {
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
             val = elem[head];
            head = (head + 1) % elem.length;
            size--;

            this.notify();

        }
        return val;
    }

    public Integer peek(){
        if(size==0){
            return null;
        }
        return elem[head];
    }

}
